<?php
namespace EasySwoole\EasySwoole;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;

use App\ServerInit\Mysql;
use App\ServerInit\Redis;
use EasySwoole\Component\Di;
class EasySwooleEvent implements Event
{

    public static function initialize()
    {
        date_default_timezone_set('Asia/Shanghai');
        Mysql::init();
        Redis::init();


    }

    public static function mainServerCreate(EventRegister $register)
    {
        Di::getInstance()->set(
        /**
         * @param $request
         * @param $response
         * 注册一个控制未找到的闭包，自己定义常量
         * @var $response   EasySwoole\Http\Response
         *
         */
            CONTROLLER_FOUND,function ($request, $response){
            $response->write('not found!');
            $response->withHeader('Content-type', 'application/json;charset=utf-8');
            $response->withStatus(200);
        });
        Di::getInstance()->set(SysConst::HTTP_CONTROLLER_POOL_MAX_NUM ,1200);
    }

    public static function onRequest(Request $request, Response $response): bool
    {
        return true;
    }

    public static function afterRequest(Request $request, Response $response): void
    {
        // TODO: Implement afterAction() method.
    }
}